﻿using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System;
using System.Xml;
using System.Data;
using System.Text;
using System.Web;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
using System.Web.UI.WebControls.WebParts;

namespace SLSlideShow
{
    [DefaultProperty("Text"),
        ToolboxData("<{0}:CustomPropertyWebPart runat=server></{0}:CustomPropertyWebPart>"),
        XmlRoot(Namespace = "SlideShow")]
    public class SlideShow : System.Web.UI.WebControls.WebParts.WebPart
    {
       
        #region Enumerations
        //enums for Drop downs
        public enum SSFontStyle
        {
            Normal=0,
            Italic
        };
        public enum SSFontWeight
        {
            Thin=0,
            ExtraLight,
            Light,
            Normal,
            Medium,
            SemiBold,
            Bold,
            ExtraBold,
            Black,
            ExtraBlack
        };
        public enum SSSlideTheme
        {
            NoTheme=0,
            SlideStack,
            RandomSlideStack,
            RandomSingle
        };
        public enum SSSpeed
        {
            VerySlow=0,
            Slow,
            Normal,
            DoubleTime,
            Fast,
            UltraFast
        };
        #endregion
        #region Attributes
        //member variables
        private bool m_includejs = true;
        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        System.ComponentModel.Category("SlideShow Behavior"),
        WebDisplayName("Include Javascript Files"),
        WebDescription("Call Javascript files, uncheck for multiple instances")]
        public bool IncludeJS
        {
            get { return m_includejs; }
            set { m_includejs = value; }
        } 

        private string m_bgcolor = "#202020";
        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        System.ComponentModel.Category("SlideShow Colors"),
        WebDisplayName("Background Color"),
        WebDescription("Background color of the SlideShow: RGB Value")]
        public string BGcolor
        {     
            get{return m_bgcolor;}
            set{m_bgcolor = value;}
        }

        private string m_bgcontentcolor = "#000000";
        [System.ComponentModel.Category("SlideShow Colors")]
        //[DefaultValue("#000000")]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Background Content Color")]
        [WebDescription("Background color of the SlideShow Content Window: RGB Value")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "BGContentColor")]
        public string BGContentColor
        {
            get { return m_bgcontentcolor; }
            set { m_bgcontentcolor = value; }
        }

        private string m_buttonbackground = "#000000";
        [System.ComponentModel.Category("SlideShow Colors")]
        //[DefaultValue("#000000")]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Button Background Color")]
        [WebDescription("Background color of the Button: RGB Value")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "ButtonBackground")]
        public string ButtonBackground
        {
            get { return m_buttonbackground; }
            set { m_buttonbackground = value; }
        }

        private string m_buttonforeground = "#FFFFFF";
        [System.ComponentModel.Category("SlideShow Colors")]
        //[DefaultValue("#FFFFFF")]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Button Foreground Color")]
        [WebDescription("Foreground color of the Buttont Window: RGB Value")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "ButtonForeground")]
        public string ButtonForeground
        {
            get { return m_buttonforeground; }
            set { m_buttonforeground = value; }
        }

        private string m_buttonborder = "#FFFFFF";
        [System.ComponentModel.Category("SlideShow Colors")]
        //[DefaultValue("#FFFFFF")]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Button Border Color")]
        [WebDescription("Border color of the Button: RGB Value")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "ButtonBorder")]
        public string ButtonBorder
        {
            get { return m_buttonborder; }
            set { m_buttonborder = value; }
        }

        private string m_playcolor = "LightGreen";
        [System.ComponentModel.Category("SlideShow Colors")]
        //[DefaultValue("LightGreen")]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Play Button Color")]
        [WebDescription("Color of the Play Button: RGB Value")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "PlayButtonColor")]
        public string PlayButtonColor
        {
            get { return m_playcolor; }
            set { m_playcolor = value; }
        }

        private string m_captionbg = "#000000";
        [System.ComponentModel.Category("SlideShow Colors")]
        //[DefaultValue("#000000")]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Caption Background Color")]
        [WebDescription("Background Color of the Caption: RGB Value")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "CaptionBG")]
        public string CaptionBG
        {
            get { return m_captionbg; }
            set { m_captionbg = value; }
        }

        private string m_captionfg = "#FFFFFF";
        [System.ComponentModel.Category("SlideShow Colors")]
        //[DefaultValue("#FFFFFF")]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Caption Foreground Color")]
        [WebDescription("Foreground Color of the Caption: RGB Value")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "CaptionFG")]
        public string CaptionFG
        {
            get { return m_captionfg; }
            set { m_captionfg = value; }
        }

        private string m_captionfont = "Verdana";
        [System.ComponentModel.Category("SlideShow Fonts")]
        //[DefaultValue("Verdana")]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Caption Font")]
        [WebDescription("Caption Font: Text Value")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "CaptionFont")]
        public string CaptionFont
        {
            get { return m_captionfont; }
            set { m_captionfont = value; }
        }

        private int m_captionfontsize = 11;
        [System.ComponentModel.Category("SlideShow Fonts")]
        //[DefaultValue(11)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Caption Font Size")]
        [WebDescription("Caption Font Size(Pt): Int Value")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "CaptionFontSize")]
        public int CaptionFontSize
        {
            get { return m_captionfontsize; }
            set { m_captionfontsize = value; }
        }

        private SSFontStyle m_captionstyle = SSFontStyle.Normal;
        [System.ComponentModel.Category("SlideShow Fonts")]
        //[DefaultValue(SSFontStyle.Normal)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Caption Font Style")]
        [WebDescription("Caption Font Style")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "CaptionFontStyle")]
        public SSFontStyle CaptionFontStyle
        {
            get { return m_captionstyle; }
            set { m_captionstyle = value; }
        }

        private SSFontWeight m_captionweight = SSFontWeight.Normal;
        [System.ComponentModel.Category("SlideShow Fonts")]
        //[DefaultValue(SSFontWeight.Normal)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Caption Font Weight")]
        [WebDescription("Caption Font Weight")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "CaptionFontWeight")]
        public SSFontWeight CaptionFontWeight
        {
            get { return m_captionweight; }
            set { m_captionweight = value; }
        }

        private float m_captionopacity = 0.7F;
        [System.ComponentModel.Category("SlideShow Fonts")]
        //[DefaultValue(.7)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Caption Opacity")]
        [WebDescription("Caption Opacity from 0-1: Float Value")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "CaptionOpacity")]
        public float CaptionOpacity
        {
            get { return m_captionopacity; }
            set { m_captionopacity = value; }
        }

        private string m_selectedthumbcolor = "Yellow";
        [System.ComponentModel.Category("SlideShow Colors")]
        //[DefaultValue("#FFFFFF")]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Selected Thumbnail Color")]
        [WebDescription("Color of the Selected Thumbnail: RGB Value")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "SelectedThumbnailColor")]
        public string SelectedThumbnailColor
        {
            get { return m_selectedthumbcolor; }
            set { m_selectedthumbcolor = value; }
        }

        private string m_trackerfg = "Silver";
        [System.ComponentModel.Category("SlideShow Colors")]
        //[DefaultValue("#FFFFFF")]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Tracker Foreground Color")]
        [WebDescription("Color of the Tracker Foreground: RGB Value")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "TrackerFG")]
        public string TrackerFG
        {
            get { return m_trackerfg; }
            set { m_trackerfg = value; }
        }

        private string m_trackerfont = "Verdana";
        [System.ComponentModel.Category("SlideShow Fonts")]
        //[DefaultValue("Verdana")]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Tracker Font")]
        [WebDescription("Tracker Font: Text Value")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "TrackerFont")]
        public string TrackerFont
        {
            get { return m_trackerfont; }
            set { m_trackerfont = value; }
        }

        private int m_trackerfontsize = 11;
        [System.ComponentModel.Category("SlideShow Fonts")]
        //[DefaultValue(11)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Caption Font Size")]
        [WebDescription("Tracker Font Size(Pt): Int Value")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "TrackerFontSize")]
        public int TrackerFontSize
        {
            get { return m_trackerfontsize; }
            set { m_trackerfontsize = value; }
        }

        private SSFontStyle m_trackerstyle = SSFontStyle.Normal;
        [System.ComponentModel.Category("SlideShow Fonts")]
        //[DefaultValue(SSFontStyle.Normal)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Tracker Font Style")]
        [WebDescription("Tracker Font Style")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "TrackerFontStyle")]
        public SSFontStyle TrackerFontStyle
        {
            get { return m_trackerstyle; }
            set { m_trackerstyle = value; }
        }

        private SSFontWeight m_trackerweight = SSFontWeight.Normal;
        [System.ComponentModel.Category("SlideShow Fonts")]
        //[DefaultValue(SSFontWeight.Normal)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Tracker Font Weight")]
        [WebDescription("Tracker Font Weight")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "TrackerFontWeight")]
        public SSFontWeight TrackerFontWeight
        {
            get { return m_trackerweight; }
            set { m_trackerweight = value; }
        }

        private int m_borderradius = 8;
        [System.ComponentModel.Category("SlideShow Appearance")]
        //[DefaultValue(8)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Border Radius")]
        [WebDescription("Radius of the Border in Pixels")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "BorderRadius")]
        public int BorderRadius
        {
            get { return m_borderradius; }
            set { m_borderradius = value; }
        }

        private int m_padding = 8;
        [System.ComponentModel.Category("SlideShow Appearance")]
        //[DefaultValue(8)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Padding")]
        [WebDescription("Padding in Pixels")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "Padding")]
        public int Padding
        {
            get { return m_padding; }
            set { m_padding = value; }
        }

        private int m_height = 360;
        [System.ComponentModel.Category("SlideShow Appearance")]
        //[DefaultValue(360)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("SlideShow Height")]
        [WebDescription("Height of SlideShow in Pixels")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "SSHeight")]
        public int SSHeight
        {
            get { return m_height; }
            set { m_height = value; }
        }

        private int m_width = 360;
        [System.ComponentModel.Category("SlideShow Appearance")]
        //[DefaultValue(360)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("SlideShow Width")]
        [WebDescription("Width of SlideShow in Pixels")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "SSWidth")]
        public int SSWidth
        {
            get { return m_width; }
            set { m_width = value; }
        }

        private string m_sslistname = string.Empty;
        [System.ComponentModel.Category("SlideShow Behavior")]
        //[DefaultValue("")]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("SharePoint ListName")]
        [WebDescription("Enter the name of the list tht you want to retrieve data from.")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "SSListName")]
        public string SSListName
        {
            get { return m_sslistname; }
            set { m_sslistname = value; }
        }

        private bool m_autoplay = true;
        [System.ComponentModel.Category("SlideShow Behavior")]
        //[DefaultValue(true)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("AutoPlay Enabled")]
        [WebDescription("Enable or Disable Autoplay of the SlidesShow")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "AutoPlay")]
        public bool AutoPlay
        {
            get { return m_autoplay; }
            set { m_autoplay = value; }
        }

        private bool m_bplaypause = true;
        [System.ComponentModel.Category("SlideShow Behavior")]
        //[DefaultValue(true)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Play Pause Button")]
        [WebDescription("Enable or Disable Play Pause Button on the SlidesShow")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "PlayPause")]
        public bool PlayPause
        {
            get { return m_bplaypause; }
            set { m_bplaypause = value; }
        }

        private bool m_bprevnext = true;
        [System.ComponentModel.Category("SlideShow Behavior")]
        //[DefaultValue(true)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Prev Next Buttons")]
        [WebDescription("Enable or Disable Prev Next Buttons on the SlidesShow")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "PrevNext")]
        public bool PrevNext
        {
            get { return m_bprevnext; }
            set { m_bprevnext = value; }
        }

        private bool m_bprevnextpage = true;
        [System.ComponentModel.Category("SlideShow Behavior")]
        //[DefaultValue(true)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Prev Next Page Buttons")]
        [WebDescription("Enable or Disable Prev Next Page Buttons on the SlidesShow")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "PrevNextPage")]
        public bool PrevNextPage
        {
            get { return m_bprevnextpage; }
            set { m_bprevnextpage = value; }
        }

        private bool m_bfullscreen = true;
        [System.ComponentModel.Category("SlideShow Behavior")]
        //[DefaultValue(true)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Fullscreen Button")]
        [WebDescription("Enable or Disable FullScreen Button on the SlidesShow")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "Fullscreen")]
        public bool Fullscreen
        {
            get { return m_bfullscreen; }
            set { m_bfullscreen = value; }
        }

        private bool m_bsave = true;
        [System.ComponentModel.Category("SlideShow Behavior")]
        //[DefaultValue(true)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Save Button")]
        [WebDescription("Enable or Disable Save Button on the SlidesShow")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "Save")]
        public bool Save
        {
            get { return m_bsave; }
            set { m_bsave = value; }
        }

        private bool m_shcaption = true;
        [System.ComponentModel.Category("SlideShow Behavior")]
        //[DefaultValue(true)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Show Captions")]
        [WebDescription("Show or Hide Caption on the SlidesShow")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "ShowHideCaption")]
        public bool ShowHideCaption
        {
            get { return m_shcaption; }
            set { m_shcaption = value; }
        }

        private bool m_shthumbs = true;
        [System.ComponentModel.Category("SlideShow Behavior")]
        //[DefaultValue(true)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Show Thumbnails")]
        [WebDescription("Show or Hide Thumbnails on the SlidesShow")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "ShowHideThumbs")]
        public bool ShowHideThumbs
        {
            get { return m_shthumbs; }
            set { m_shthumbs = value; }
        }

        private bool m_shtracker = true;
        [System.ComponentModel.Category("SlideShow Behavior")]
        //[DefaultValue(true)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("Show Tracker")]
        [WebDescription("Show or Hide Tracker on the SlidesShow")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "ShowHideTracker")]
        public bool ShowHideTracker
        {
            get { return m_shtracker; }
            set { m_shtracker = value; }
        }

        private SSSlideTheme m_stheme = SSSlideTheme.NoTheme;
        [System.ComponentModel.Category("SlideShow Behavior")]
        //[DefaultValue(SSSlideTheme.NoTheme)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("SlideShow Theme")]
        [WebDescription("Choose the Positioning Theme for the SlidesShow")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "ShowTheme")]
        public SSSlideTheme ShowTheme
        {
            get { return m_stheme; }
            set { m_stheme = value; }
        }

        private SSSpeed m_sspeed= SSSpeed.Normal;
        [System.ComponentModel.Category("SlideShow Behavior")]
        //[DefaultValue(SSSpeed.Normal)]
        [Personalizable(PersonalizationScope.Shared)]
        [WebDisplayName("SlideShow Speed")]
        [WebDescription("Choose the Speed of the transitions for the SlidesShow")]
        [WebBrowsable(true)]
        //[XmlElement(ElementName = "ShowSpeed")]
        public SSSpeed ShowSpeed
        {
            get { return m_sspeed; }
            set { m_sspeed = value; }
        }
        #endregion
        protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
        {
            Random rd = new Random();
            int rdm = rd.Next();
            //Generates random number which postpends the first four digits into the slide name so it can support multiple slide libraries on one page
            string slidesetname = "Slide_" + rdm.ToString().Substring(0, 4);
            string slideshowname = "Show_" + rdm.ToString().Substring(0, 4);
            //Lets get all the items from the list, but first create a secondary stringbuilder.
            SPWeb mySite = SPContext.Current.Web;
            StringBuilder listdata = new StringBuilder();
            bool errorfree = true;
            if (SSListName == string.Empty)
            {
                listdata.AppendLine("<div class=\"slideshowerror\">Please Set the List Name in the SlideShow behaviors property. </div>");
                errorfree = false;
            }
            else
            {
                try
                {
                    SPList myPicLib = mySite.Lists[SSListName];
                    if (myPicLib == null) { throw new Exception("List Retreival Returned Null"); }
                    if (myPicLib.BaseTemplate != SPListTemplateType.PictureLibrary) { throw new Exception("List Selected is Not A Picture Library-" + myPicLib.BaseTemplate.ToString()); }
                        
                        SPListItemCollection myItems = myPicLib.Items;
                        listdata.AppendLine("<script id=\"" + slidesetname + "\" type=\"text/xml\"><slides baseUrl=\"\">");
                        foreach (SPListItem myItem in myItems)
                        {
                            

                            //example item <slide imageUrl="/Pictures/image.JPG" thumbnailUrl="/Pictures/_t/image_JPG.jpg" caption="Image"/>
                            // FileRef LinkFilenameNoMenu Title SPBuiltInFieldId.Title
                           listdata.AppendFormat("<slide imageUrl=\"{0}\" thumbnailUrl=\"{1}\" caption=\"{2}\"/>", myItem[SPBuiltInFieldId.FileRef].ToString(), myItem[SPBuiltInFieldId.EncodedAbsThumbnailUrl].ToString(), ((myItem[SPBuiltInFieldId.Title] != null) ? myItem[SPBuiltInFieldId.Title].ToString() : string.Empty));
                           
                        }
                        listdata.AppendLine("</slides></script>");
                    
                    
                }
                catch (Exception ex)
                {
                    listdata.AppendLine("<div class=\"slideshowerror\">Specified list does not exist or cannot be accessed<br/>" + ex.Message.ToString() + "</div>");
                    errorfree = false; 

                }
            }
            if (errorfree)
            {
                
                //Specifies the name of the strings that are in the LAYOUTS/SLSlideShow folder, Ordering is Specific!
                string[] scripts = new string[] { "Silverlight.min.js", "SilverlightSpy.min.js", "SlideshowCreate.min.js", "Slideshow.min.js", "Slide.min.js" };

                //writer.Write("I'm alive!!");
                //SPWeb spw = SPContext.Current.Web;
                StringBuilder sb = new StringBuilder();
                sb.Append("<center><div id=\""+slideshowname+"\">");
                sb.Append("<style type=\"text/css\">#slideshow{text-align:center;}.slideshowerror{color:red;}</style>");

                if (IncludeJS)
                {
                    for (int i = 0; i < scripts.Length; i++)
                    {
                        //Lets iterate through all the script names and append them to the output
                        sb.Append("<script type=\"text/javascript\" src=\"_layouts/SLSlideShow/" + scripts[i] + "\"></script>");
                    }
                }

                //Lets create the javascript that creates the slideshow

                //I realized too late that I could have just used .AppendLine()..Doh
                sb.AppendLine("<script type=\"text/javascript\">");
                sb.AppendLine("createSlideshow('" + slideshowname + "', {");
                sb.AppendLine("width: '" + SSWidth + "',");
                sb.AppendLine("height: '" + SSHeight + "',");
                sb.AppendLine("slidesSource: '#" + slidesetname + "',");
                sb.AppendLine("background: '" + BGcolor + "',");
                sb.AppendLine("buttonBackground: '" + ButtonBackground + "',");
                sb.AppendLine("buttonForeground: '" + ButtonForeground + "',");
                sb.AppendLine("buttonBorderColor: '" + ButtonBorder + "',");
                sb.AppendLine("buttonPlayForeground: '" + PlayButtonColor + "',");
                sb.AppendLine("captionBackground: '" + CaptionBG + "',");
                sb.AppendLine("captionForeground: '" + CaptionFG + "',");
                sb.AppendLine("captionFontFamily: '" + CaptionFont + "',");
                sb.AppendLine("captionFontSize: " + CaptionFontSize + ",");
                sb.AppendLine("captionFontStyle: '" + returnEnumStyle(CaptionFontStyle) + "',");
                sb.AppendLine("captionFontWeight: '" + returnEnumWeight(CaptionFontWeight) + "',");
                sb.AppendLine("captionOpacity: " + CaptionOpacity.ToString() + ",");
                sb.AppendLine("contentBackground: '" + BGContentColor + "',");
                sb.AppendLine("selectedThumbnailBorderColor: '" + SelectedThumbnailColor + "',");
                sb.AppendLine("trackerForeground: '" + TrackerFG + "',");
                sb.AppendLine("trackerFontFamily: '" + TrackerFont + "',");
                sb.AppendLine("trackerFontSize: " + TrackerFontSize + ",");
                sb.AppendLine("trackerFontStyle: '" + returnEnumStyle(TrackerFontStyle) + "',");
                sb.AppendLine("trackerFontWeight: '" + returnEnumWeight(TrackerFontWeight) + "',");
                sb.AppendLine("borderRadius: " + BorderRadius + ",");
                sb.AppendLine("padding: " + Padding + ",");
                sb.AppendLine("captionVisible: " + ShowHideCaption.ToString().ToLower() + ",");
                sb.AppendLine("thumbnailsVisible: " + ShowHideThumbs.ToString().ToLower() + ",");
                sb.AppendLine("trackerVisible: " + ShowHideTracker.ToString().ToLower() + ",");
                string butOptions = string.Empty;

                //Need to process options for buttons            
                string optionsout = string.Empty;
                if (PlayPause) { optionsout = optionAttach(optionsout, "BUTTON_PLAYPAUSE"); }
                if (PrevNext) { optionsout = optionAttach(optionsout, "BUTTON_PREVNEXT"); }
                if (PrevNextPage) { optionsout = optionAttach(optionsout, "BUTTON_PREVNEXTPAGE"); }
                if (Fullscreen) { optionsout = optionAttach(optionsout, "BUTTON_FULLSCREEN"); }
                if (Save) { optionsout = optionAttach(optionsout, "BUTTON_SAVE"); }
                //sb.AppendLine("buttonOptions: BUTTON_PLAYPAUSE | BUTTON_PREVNEXT | BUTTON_PREVNEXTPAGE | BUTTON_FULLSCREEN | BUTTON_SAVE,");
                sb.AppendLine("buttonOptions: " + optionsout + ",");

                sb.AppendLine("autoPlay: " + AutoPlay.ToString().ToLower() + ",");
                sb.AppendLine("slideSettings: {");
                switch (ShowSpeed)
                {
                    case SSSpeed.DoubleTime:
                        sb.AppendLine("speedRatio: 2,");
                        break;
                    case SSSpeed.Fast:
                        sb.AppendLine("speedRatio: 4,");
                        break;
                    case SSSpeed.Normal:
                        sb.AppendLine("speedRatio: 1,");
                        break;
                    case SSSpeed.Slow:
                        sb.AppendLine("speedRatio: .1,");
                        break;
                    case SSSpeed.UltraFast:
                        sb.AppendLine("speedRatio: 6,");
                        break;
                    case SSSpeed.VerySlow:
                        sb.AppendLine("speedRatio: .4,");
                        break;
                    default:
                        sb.AppendLine("speedRatio: 1,");
                        break;
                }
                switch (ShowTheme)
                {
                    case SSSlideTheme.NoTheme:
                        sb.AppendLine("theme: THEME_NONE");
                        break;
                    case SSSlideTheme.RandomSingle:
                        sb.AppendLine("theme: THEME_RANDOM_SLIDE");
                        break;
                    case SSSlideTheme.RandomSlideStack:
                        sb.AppendLine("theme: THEME_RANDOM_STACK");
                        break;
                    case SSSlideTheme.SlideStack:
                        sb.AppendLine("theme: THEME_STACK");
                        break;
                    default:
                        sb.AppendLine("theme: THEME_NONE");
                        break;
                }

                sb.AppendLine("}});");
                sb.AppendLine("</script>");




                sb.AppendLine(listdata.ToString());

                sb.AppendLine("</div></center>");
                
                
                writer.WriteLine(sb.ToString());
                
            }
            else
            {
                writer.WriteLine(listdata.ToString());
            }
        }
        private string optionAttach(string inputoptions, string stringtoattach)
        {
            if (inputoptions == string.Empty)
            {
                return stringtoattach;
            }
            else
            {
                return inputoptions + " | " + stringtoattach;
            }            
        }
        private string returnEnumStyle(SSFontStyle fs)
        {
            string ret = string.Empty;
            switch (fs)
            {
                case SSFontStyle.Italic:
                    ret = "Italic";
                    break;
                case SSFontStyle.Normal:
                    ret = "Normal";
                    break;
                default:
                    ret = "Normal";
                    break;
            }
            return ret;
        }
        private string returnEnumWeight(SSFontWeight fw)
        {
            string ret = string.Empty;
            switch (fw)
            {
                case SSFontWeight.Thin:
                    ret = "Thin";
                    break;
                case SSFontWeight.SemiBold:
                    ret = "SemiBold";
                    break;
                case SSFontWeight.Normal:
                    ret = "Normal";
                    break;
                case SSFontWeight.Medium:
                    ret = "Normal";
                    break;
                case SSFontWeight.Light:
                    ret = "Light";
                    break;
                case SSFontWeight.ExtraLight:
                    ret = "ExtraLight";
                    break;
                case SSFontWeight.ExtraBold:
                    ret = "ExtraBold";
                    break;
                case SSFontWeight.ExtraBlack:
                    ret = "ExtraBlack";
                    break;
                case SSFontWeight.Bold:
                    ret = "Bold";
                    break;
                case SSFontWeight.Black:
                    ret = "Black";
                    break;
                default:
                    ret = "Normal";
                    break;
            }
            return ret;
        }
        private string returnThumbnail(string url)
        {
            //data thats going to be received is
            // /Pictures/betsy with halo.JPG needs to be /Pictures/_t/betsy with halo_JPG.jpg
            string ret = string.Empty;
            string preurl = url.Substring(0,url.LastIndexOf("/")+1) ;
            string posturl = url.Substring(url.LastIndexOf("/") + 1, url.LastIndexOf(".") - url.LastIndexOf("/")-1);
            string filetype = url.Substring(url.LastIndexOf(".")+1);
            ret = preurl + "_t/"+posturl+"_"+filetype.ToUpper()+"."+filetype.ToLower();
            return ret;
        }
    }
}